<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
</head>
  <title>审批角色管理</title>
  <style type="text/css">
  	.layui-form-select dl{
		max-height: 150px; // 原值为300，调节高度建议为50的倍数
	}
	.layui-form-label{width: 130px;}
  </style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-card">
      <!-- 查询区域  -->
      <div id="query-form" class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">审批角色</label>
				<div class="layui-input-inline">
					<input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">审批角色编码</label>
				<div class="layui-input-inline">
					<input type="text" name="code" placeholder="请输入" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">审批角色范围</label>
				<div class="layui-input-inline">
					<select id="query-form-type" name="type">
						<option value="">请选择-审批角色范围</option>
						<option value="1">集团总部</option>
						<option value="2">区域公司</option>
						<option value="3">项目公司</option>
						<option value="4">部门负责人</option>
						<option value="5">公司法人</option>
					</select>
				</div>
			</div>
			<%--<div class="layui-inline">
				<label class="layui-form-label">状态</label>
				<div class="layui-input-inline">
					<select id="query-form-state" name="state">
						<option value="">请选择-状态</option>
						<option value="1">启用</option>
						<option value="0">禁用</option>
					</select>
				</div>
			</div>--%>
			<div class="layui-inline">
				<button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-dept-search">
					<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
				</button>
				<button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-reset">
					<i class="layui-icon layui-icon-fonts-clear  layuiadmin-button-btn"></i>重置
				</button>
			</div>
        </div>
      </div>
  	  <!-- 按钮区域  -->
      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
          <shiro:hasPermission name="SAVE_DEPT">
          	<button class="layui-btn layuiadmin-btn-admin " data-type="add">
          	 	<i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>新增
          	</button>
          </shiro:hasPermission>
        </div>
        <!-- 数据表单 -->
        <table id="LAY-dept-manage" lay-filter="LAY-dept-manage"></table>

        <div class="layui-form" lay-filter="add_form" id="add_form" style="padding: 20px 30px 0 0;display:none">
		    <div class="layui-form-item">
		    	<div class="layui-inline">
			      	<label class="layui-form-label">审批角色编码</label>
			      	<div class="layui-input-inline">
						<input type="text" name="code" maxlength="50" lay-verify="required" placeholder="请输入岗位组编码" autocomplete="off" class="layui-input">
					</div>
		      	</div>
	      	</div>
	      	<div class="layui-form-item">
		      	<div class="layui-inline">
			    	<label class="layui-form-label">审批角色名称</label>
				    <div class="layui-input-inline">
						<input type="text" name="name" maxlength="50" lay-verify="required" placeholder="请输入岗位组名称" autocomplete="off" class="layui-input">

				    </div>
			    </div>
			</div>
			<div class="layui-form-item">
		    	<div class="layui-inline">
			      	<label class="layui-form-label">审批角色范围</label>
			      	<div class="layui-input-inline">
			        	<select name="type" lay-verify="required">
							<option value="1" selected="selected">集团总部</option>
							<option value="2">区域公司</option>
							<option value="3">项目公司</option>
							<option value="4">部门负责人</option>
							<option value="5">公司法人</option>
						</select>
			      	</div>
		      	</div>
	      	</div>
	      	<div class="layui-form-item">
		    	<div class="layui-inline">
			      	<label class="layui-form-label">审批角色描述</label>
			      	<div class="layui-input-inline">
			        	<textarea style="width: 200px;height: 60px" name="memo"></textarea>
			      	</div>
		      	</div>
		    </div>

			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">审批角色类型</label>
					<div class="layui-input-inline">
						<input type="radio" name="roleType"  value="1" title="岗位" checked>
						<input type="radio" name="roleType"  value="2" title="固定人员">

					</div>
				</div>
			</div>

		    <div class="layui-form-item layui-hide">
		      	<input type="button" lay-submit lay-filter="add_form_submit" id="add_form_submit" value="确认">
		    </div>
	  	</div>

	  	<!-- 编辑窗口 -->
        <div class="layui-form" lay-filter="edit_form" id="edit_form" style="padding: 20px 30px 0 0;display:none">
        	<input type="hidden" name="id" id="editAccountId" />
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">审批角色编码</label>
					<div class="layui-input-inline">
						<input type="text" name="code" maxlength="50" lay-verify="required" placeholder="请输入审批角色编码" autocomplete="off" class="layui-input">
						<input type="hidden" name="id"  id="groupId">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">审批角色名称</label>
					<div class="layui-input-inline">
						<input type="text" name="name" maxlength="50" lay-verify="required" placeholder="请输入审批角色名称" autocomplete="off" class="layui-input">

					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">审批角色范围</label>
					<div class="layui-input-inline">
						<select name="type" id="postType">
							<option value="1">集团总部</option>
							<option value="2">区域公司</option>
							<option value="3">项目公司</option>
							<option value="4">部门负责人</option>
							<option value="5">公司法人</option>
						</select>
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">审批角色描述</label>
					<div class="layui-input-inline">
						<textarea style="width: 200px;height: 60px" name="memo"></textarea>
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">审批角色类型</label>
					<div class="layui-input-inline">
						<input type="radio" lay-filter="roleType" name="roleType"  value="1" title="岗位"  >
						<input type="radio" lay-filter="roleType" name="roleType"  value="2" title="固定人员">

					</div>
				</div>
			</div>
		    <div class="layui-form-item layui-hide">
		      <input type="button" lay-submit lay-filter="edit_form_submit" id="edit_form_submit" value="确认">
		    </div>
		    <!-- 岗位明细table -->
        	<table id="LAY-post-detail" lay-filter="LAY-post-detail"></table>
	  	</div>

	  	<!-- 新增岗位window -->
	  	<div class="layui-form" lay-filter="add_detail_from" id="add_detail_from" style="padding: 20px 30px 0 0;display:none">
	  		<input type="hidden" name="orgId"/>
	  		<input type="hidden" name="deptId"/>
		    <div class="layui-form-item">
		      	<label class="layui-form-label">岗位名称</label>
		      	<div class="layui-inline">
			      	<input type="text" id="postName" name="postName" maxlength="30" lay-verify="required" placeholder="请输入岗位" autocomplete="off" class="layui-input" lay-filter="add_post_name" >
					<%--<input type="hidden" id="groupId" name="groupId">
					<input type="hidden" id="type" name="type">--%>
				</div>
				<div class="layui-inline">
					<button class="layui-btn layui-btn-sm" lay-filter="post_name_search" onclick="changePost()" >
						<i class="layui-icon layuiadmin-button-btn"></i>查询
					</button>
				</div>
		    </div>
			<div class="layui-form-item"  id="search_text" style="text-align: center">
			</div>

		    <div class="layui-form-item layui-hide">
		      <input type="button" lay-submit lay-filter="add_detail_from_submit" id="add_detail_from_submit" value="确认">
		    </div>
	  	</div>

		  <div class="layui-form" lay-filter="add_user_from" id="add_user_from" style="padding: 20px 30px 0 0;display:none">
			  <input type="hidden" name="orgId"/>
			  <input type="hidden" name="deptId"/>
			  <div class="layui-form-item">
				  <label class="layui-form-label">人员姓名</label>
				  <div class="layui-inline">
					  <input type="text" id="userName" name="postName" maxlength="30" lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input" lay-filter="add_user_name" >
				  </div>
				  <div class="layui-inline">
					  <button class="layui-btn layui-btn-sm" lay-filter="post_name_search" onclick="changeUser()" >
						  <i class="layui-icon layuiadmin-button-btn"></i>查询
					  </button>
				  </div>
			  </div>
			  <div class="layui-form-item"  id="search_text2" style="text-align: center">
			  </div>

			  <div class="layui-form-item layui-hide">
				  <input type="button" lay-submit lay-filter="add_user_from_submit" id="add_user_from_submit" value="确认">
			  </div>
		  </div>

	  	<!-- 编辑明细window -->
	  	<div class="layui-form" lay-filter="edit_detail_from" id="edit_detail_from" style="padding: 20px 30px 0 0;display:none">
	  		<input type="hidden" name="id" />
	  		<input type="hidden" name="orgId"/>
	  		<input type="hidden" name="deptId"/>
		    <div class="layui-form-item">
		      	<label class="layui-form-label">岗位名称</label>
		      	<div class="layui-input-inline">
			      	<input type="text" name="postName" maxlength="30" lay-verify="required" placeholder="请输入岗位名称" autocomplete="off" class="layui-input">
		      	</div>
		    </div>
		    <div class="layui-form-item">
		    	<label class="layui-form-label">岗位状态</label>
		    	<div class="layui-input-inline">
		    		<infopub:select entireName="-状态" name="state" layVerify="required" type="dic" groupNo="A00010020"></infopub:select>
		    	</div>
		  	</div>
		    <div class="layui-form-item layui-hide">
		      <input type="button" lay-submit lay-filter="edit_detail_from_submit" id="edit_detail_from_submit" value="确认">
		    </div>
	  	</div>

	  	<!-- 详情窗口 -->
        <div class="layui-form" lay-filter="detail_form" id="detail_form" style="padding: 20px 30px 0 0;display:none">
		    <%--<div class="layui-form-item">
		    	<div class="layui-inline">
			      	<label class="layui-form-label">公司名称</label>
			      	<div class="layui-input-inline">
			        	<input type="text" name="orgName" style="border:0px;width:220px;" readonly="readonly" class="layui-input">
			      	</div>
		      	</div>
	      	</div>
	      	<div class="layui-form-item">
		      	<div class="layui-inline">
			    	<label class="layui-form-label">上级部门（选填）</label>
				    <div class="layui-input-inline">
			        	<input type="text" name="parentDeptName" style="border:0px;" readonly="readonly" class="layui-input">
				    </div>
			    </div>
			</div>
			<div class="layui-form-item">
		    	<div class="layui-inline">
			      	<label class="layui-form-label">部门层级</label>
			      	<div class="layui-input-inline">
			        	<input type="text" name="levelIdx" style="border:0px;" readonly="readonly" class="layui-input">
			      	</div>
		      	</div>
	      	</div>
	      	<div class="layui-form-item">
		    	<div class="layui-inline">
			      	<label class="layui-form-label">部门名称</label>
			      	<div class="layui-input-inline">
			        	<input type="text" name="deptName" style="border:0px;" readonly="readonly" class="layui-input">
			      	</div>
		      	</div>
		    </div>
		    <div class="layui-form-item">
		    	<div class="layui-inline">
		    		<label class="layui-form-label">编制人数</label>
		      		<div class="layui-input-inline">
		        		<input type="text" name="deptMaxNum" style="border:0px;" readonly="readonly" class="layui-input">
		      		</div>
			    </div>
		    </div>
		    <div class="layui-form-item">
		    	<div class="layui-inline">
		    		<label class="layui-form-label">部门负责人</label>
		      		<div class="layui-input-inline">
		        		<input type="text" name="deptLeader" style="border:0px;" readonly="readonly" class="layui-input">
		      		</div>
			    </div>
		    </div>
		    <div class="layui-form-item">
			    <div class="layui-inline">
			    	<label class="layui-form-label">部门岗位</label>
			    	<div class="layui-input-inline">
				   		<textarea id="detail_postName" name="postName" readonly="readonly" class="layui-textarea" style="width:350px;height:90px;"></textarea>
			    	</div>
		    	</div>
		  	</div>
		    <div class="layui-form-item layui-hide">
		      <input type="button" lay-submit lay-filter="detail_form_submit" id="detail_form_submit" value="确认">
		    </div>--%>
				<table id="group-post-detail" lay-filter="group-post-detail"></table>
	  	</div>

      </div>
    </div>
  </div>
  <script type="text/html" id="table-toolbar-addPost">
	  <div class="layui-btn-container">
		  <button class="layui-btn layui-btn-sm" lay-event="addPost">
			  <i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>新增岗位
		  </button>
	  </div>
  </script>
  <script type="text/html" id="table-toolbar-addUser">
	  <div class="layui-btn-container">
		  <button class="layui-btn layui-btn-sm" lay-event="addUser">
			  <i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>新增人员
		  </button>
	  </div>
  </script>
  <script>
  	layui.config({
    	base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  	}).extend({
    	index: 'lib/index' //主入口模块
  	}).use(['index', 'table', 'set', 'transfer', 'laydate'], function(){
    	var $ = layui.$
    	,form = layui.form
    	,table = layui.table
    	,laydate = layui.laydate;

 		// 正则校验
    	form.verify({
    		//验证汉字
    	    CHS: [
    	    	/^[\u0391-\uFFE5]+$/
    	    	,'只能输入汉字'
    	  	],
	    	//大于0的正整数
		  	intNumber:[
				/^[1-9]\d*$/
				,'请输入正确的数字'
		  	]
		});

		form.on('radio(roleType)', function (data) {
			if( data.elem.checked){　　　　　　//判断当前多选框是选中还是取消选中
				console.log('当前选中'+data.value);
				if(data.value=='1'){
					table.render({
						elem: '#LAY-post-detail'
						,url: basePath + '/post/queryDataByGroupId?groupId='+$("#groupId").val()+"&roleType=1" //请求数据接口
						,toolbar:'#table-toolbar-addPost'
						,defaultToolbar: []
						,cols: [[
							{type: 'checkbox', fixed: 'left'}
							,{field: 'orgId', title: '组织',width:200}
							,{field: 'deptId', title: '部门',width:180}
							,{field: 'postName', title: '岗位名称'}
							/*,{field: 'state', title: '岗位状态', templet: function(d){
									if(d.state == 1){
										return "启用中";
									}else{
										return '<span class="layui-badge layui-bg-cyan">已停用</span>' ;
									}
								}
							}*/
							,{title: '操作', width: 110, align:'center', fixed: 'right', templet: function(d){
									var optStr ="";
									optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="editPost"><i class="layui-icon layui-icon-edit"></i>删除</a>';
									return optStr;
								}
							}
						]]
						,page: true
						,limit: 10
						,limits:[5,10,20,30,50]
					});
				}else{
					table.render({
						elem: '#LAY-post-detail'
						,url: basePath + '/post/queryDataByGroupId?groupId='+$("#groupId").val()+"&roleType=2" //请求数据接口
						,toolbar:'#table-toolbar-addUser'
						,defaultToolbar: []
						,cols: [[
							{type: 'checkbox', fixed: 'left'}
							,{field: 'orgName', title: '组织',width:250}
							,{field: 'deptName', title: '部门',width:180}
							,{field: 'name', title: '姓名'}
							,{title: '操作', width: 110, align:'center', fixed: 'right', templet: function(d){
									var optStr ="";
									optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="editPost"><i class="layui-icon layui-icon-edit"></i>删除</a>';
									return optStr;
								}
							}
						]]
						,page: true
						,limit: 10
						,limits:[5,10,20,30,50]
					});
				}

			}else{
				//alert('取消选中')
			}
			var value = data.value;   //  当前选中的value值
		});

    	// 表单
    	table.render({
      		elem: '#LAY-dept-manage'
      		,url: basePath + '/postGroup/queryDataByCondition' //请求数据接口
      		,cols: [[
				{type: 'checkbox', fixed: 'left'}
				,{field: 'name', title: '审批角色名称',width:250}
				,{field: 'code', title: '审批角色编码',width:150}
				, {field: 'type', title: '审批角色范围', width: 120, templet: function(d){
					if(d.type=='1')return '集团总部';
					if(d.type=='2')return '区域公司';
					if(d.type=='3')return '项目公司';
					if(d.type=='4')return '部门负责人';
					if(d.type=='5')return '公司法人';
					}
				}
				,{field: 'memo', title: '审批角色描述'}
				,{field: 'roleType', title: '审批角色类型',width:120,templet: function (d) {
						if(d.roleType=='1')return '岗位';
						if(d.roleType=='2')return '固定人员';
					}}
				/*,{field: 'state', title: '状态',width:90, templet: function (d) {//fixed: 'right'
						if(d.state==1){
							return "启用";
						}else{return '<span class="layui-badge layui-bg-cyan">禁用</span>' ;}
					}
				}*/
				,{field: 'addTime', title: '创建时间',width:150, templet: function(d){
						return layui.util.toDateString(d.addTime,"yyyy-MM-dd HH:mm:ss");
					}
				}
        		,{title: '操作',  align:'center', fixed: 'right',width:170, templet: function(d){
      	  				var optStr ="";
						optStr += '<a class="layui-btn layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-form"></i>查看</a>';
						optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>';
						/*if(d.state == 0){//状态为停用
							optStr += '<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="use"><i class="layui-icon layui-icon-ok"></i>启用</a>';
						}else if(d.state == 1){//状态为启用
							optStr += '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="freeze"><i class="layui-icon layui-icon-pause"></i>停用</a>';
						}*/
			  		  	return optStr;
        			}
        		}
      			]]
      		,page: true
      		,limit: 10
    	});

		//监听搜索
		form.on('submit(LAY-dept-search)', function(data){
			//执行重载
			table.reload('LAY-dept-manage', {page: {curr: 1},
				where: trimData(data)
			});
		});
		//重置清空
		form.on('submit(LAY-user-back-reset)', function(data){
			reset_form('query-form');
			//额外处理select
			$("#query-form-state").val('');
			if('${bindOrgId}'==null||'${bindOrgId}'==""){
				$("#query-select-orgId").val('${superOrgId}');
			}else{
				$("#query-select-orgId").val('${bindOrgId}');
			}
			form.render();
		});

    	// 监听操作列
    	table.on('tool(LAY-dept-manage)', function(obj){
      		var data = obj.data;
      		if(obj.event === 'use'){
          		layer.confirm('确定启用？',{icon:3, title :'提示'}, function(index){
          			$.ajax({
  						type : 'post',
  						url : basePath + '/postGroup/updateStatus?id=' + data.id,
  						success:function(result){
  							if(result.success){
  								table.reload('LAY-dept-manage'); //数据刷新
  								layer.close(index);
  							}else{
  								layer.msg(result.msg,{icon: 7});
  				  			}
  						}
  					});
          		});
      		}else if(obj.event === 'freeze'){
          		layer.confirm('确定停用？',{icon:3, title :'提示'}, function(index){
          			$.ajax({
  						type : 'post',
  						url : basePath + '/postGroup/updateStatus?id=' + data.id,
  						success:function(result){
  							if(result.success){
  								table.reload('LAY-dept-manage'); //数据刷新
  								layer.close(index);
  							}else{
  								layer.msg(result.msg,{icon: 7});
  				  			}
  						}
  					});
          		});
      		} else if(obj.event === 'edit'){

      			form.val('edit_form',data); // 填充原值
				$('#search_text').html("");
      			if(data.roleType=='1'){
					//岗位table渲染
					table.render({
						elem: '#LAY-post-detail'
						,url: basePath + '/post/queryDataByGroupId?groupId='+data.id+"&roleType="+data.roleType //请求数据接口
						,toolbar:'#table-toolbar-addPost'
						,defaultToolbar: []
						,cols: [[
							{type: 'checkbox', fixed: 'left'}
							,{field: 'orgId', title: '组织',width:250}
							,{field: 'deptId', title: '部门',width:180}
							,{field: 'postName', title: '岗位名称'}
							/*,{field: 'state', title: '岗位状态', templet: function(d){
									if(d.state == 1){
										return "启用中";
									}else{
										return '<span class="layui-badge layui-bg-cyan">已停用</span>' ;
									}
								}
							}*/
							,{title: '操作', width: 100, align:'center', fixed: 'right', templet: function(d){
									var optStr ="";
									optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="editPost"><i class="layui-icon layui-icon-edit"></i>删除</a>';
									return optStr;
								}
							}
						]]
						,page: true
						,limit: 10
						,limits:[5,10,20,30,50]
					});
				}else{
					table.render({
						elem: '#LAY-post-detail'
						,url: basePath + '/post/queryDataByGroupId?groupId='+data.id+"&roleType="+data.roleType //请求数据接口
						,toolbar:'#table-toolbar-addUser'
						,defaultToolbar: []
						,cols: [[
							{type: 'checkbox', fixed: 'left'}
							,{field: 'orgName', title: '组织',width:250}
							,{field: 'deptName', title: '部门',width:180}
							,{field: 'name', title: '姓名'}
							,{title: '操作', width: 100, align:'center', fixed: 'right', templet: function(d){
									var optStr ="";
									optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="editPost"><i class="layui-icon layui-icon-edit"></i>删除</a>';
									return optStr;
								}
							}
						]]
						,page: true
						,limit: 10
						,limits:[5,10,20,30,50]
					});
				}

      			layer.open({
            		type: 1
            		,title: '编辑审批角色'
            		,content: $('#edit_form')
            		,area: layui.admin.screen() < 2 ? ['80%', '95%'] : ['720px','95%']
            		,btn: ['确定', '取消']
            		,btnAlign: 'c'
            		,yes: function(index, layero){
          	  			var submitID = 'edit_form_submit'
          		  		,submit = layero.contents().find('#'+ submitID);
          	  			//监听提交
          	  			form.on('submit('+ submitID +')', function(data){
                			var field = data.field; //获取提交的字段
                			//提交 Ajax 成功后，静态更新表格中的数据
                			$.ajax({
                    			type : 'post',
  								url : basePath + '/postGroup/save',
                    			data: field,
  								success:function(result){
  									if(result.success){
                						table.reload('LAY-dept-manage'); //数据刷新
                						layer.close(index); //关闭弹层
  									}else{
  										layer.msg(result.msg,{icon: 7});
  					  				}
  								}
                			});
              			});
              		submit.trigger('click');
           		}
          	});
       	} else if(obj.event === 'view'){
  			//form.val('detail_form',data); // 填充原值
				console.log(data)
  			/*if(data.postInfos.length > 0){
  				var postName = '';
  				for(var i in data.postInfos){
  					var postInfo = data.postInfos[i];
  					postName = postName + postInfo.postName + "；";
  				}
  				$("#detail_postName").val(postName);
  			}*/
  			layer.open({
        		type: 1
        		,title: '审批角色信息'
        		,content: $('#detail_form')
        		,area: layui.admin.screen() < 2 ? ['80%', '520px'] : ['720px','520px']
      		});
				if(data.roleType=='1'){
					//岗位table渲染
					table.render({
						elem: '#group-post-detail'
						,url: basePath + '/post/queryDataByGroupId?groupId='+data.id+"&roleType="+data.roleType //请求数据接口
						,defaultToolbar: []
						,cols: [[
							{type: 'checkbox', fixed: 'left'}
							,{field: 'orgId', title: '组织',width:300}
							,{field: 'deptId', title: '部门',width:150}
							,{field: 'postName', title: '岗位名称'}
							/*,{field: 'state', title: '岗位状态', templet: function(d){
									if(d.state == 1){
										return "启用中";
									}else{
										return '<span class="layui-badge layui-bg-cyan">已停用</span>' ;
									}
								}
							}*/
							/*,{title: '操作', width: 110, align:'center', fixed: 'right', templet: function(d){
									var optStr ="";
									optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="editPost"><i class="layui-icon layui-icon-edit"></i>删除</a>';
									return optStr;
								}
							}*/
						]]
						,page: true
						,limit: 10
						,limits:[5,10,20,30,50]
					});
				}else{
					table.render({
						elem: '#group-post-detail'
						,url: basePath + '/post/queryDataByGroupId?groupId='+data.id+"&roleType="+data.roleType //请求数据接口
						,defaultToolbar: []
						,cols: [[
							{type: 'checkbox', fixed: 'left'}
							,{field: 'orgName', title: '组织',width:300}
							,{field: 'deptName', title: '部门',width:200}
							,{field: 'name', title: '姓名'}
							/*,{title: '操作', width: 110, align:'center', fixed: 'right', templet: function(d){
									var optStr ="";
									optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="editPost"><i class="layui-icon layui-icon-edit"></i>删除</a>';
									return optStr;
								}
							}*/
						]]
						,page: true
						,limit: 10
						,limits:[5,10,20,30,50]
					});
				}
   		}
    	});

     	// 岗位table监听toolbar
        table.on('toolbar(LAY-post-detail)', function(obj){
          	var data = obj.data;
          	if(obj.event === 'addPost'){
          		layer.open({
    	        	  type: 1
    	        	  ,title: '添加岗位'
    	        	  ,content: $('#add_detail_from')
    	        	  ,area: layui.admin.screen() < 2 ? ['80%', '210px'] : ['480px','210px']
    	        	  ,btn: ['添加', '取消']
    	        	  ,btnAlign: 'c'
    	        	  ,yes: function(index, layero){
    	        		  var submitID = 'add_detail_from_submit'
    	            		,submit = layero.contents().find('#'+ submitID);
    	        		  //监听提交
    	        		  form.on('submit('+ submitID +')', function(data){
    	        			  var field = data.field; //获取提交的字段
    	        			  //提交 Ajax 成功后，静态更新表格中的数据
    	        			  $.ajax({
    	        				  type : 'post',
    	        				  url : basePath + '/postGroup/savePost',
    	        				  data: {
									  "postName" :$("#postName").val(),
									  "type":$("#postType").val(),
									  "groupId":$("#groupId").val(),
									  "roleType":1
								  },
    	        				  success:function(result){
    	        					  if(result.success){
    	        						  table.reload('LAY-post-detail'); //数据刷新
    	        						  layer.close(index); //关闭弹层
    	        						  clean_form("add_detail_from");//清空表单
    	        					  }else{
    	        						  layer.msg(result.msg,{icon: 7});
    	        					  }
    	        				  }
    	              		 });
    	            	});
    	            submit.trigger('click');
    	          }
    	        });
				clean_form("add_detail_from");//清空表单
          	}else if(obj.event === 'addUser'){
				layer.open({
					type: 1
					,title: '添加人员'
					,content: $('#add_user_from')
					,area: layui.admin.screen() < 2 ? ['80%', '210px'] : ['480px','210px']
					,btn: ['添加', '取消']
					,btnAlign: 'c'
					,yes: function(index, layero){
						var submitID = 'add_user_from_submit'
								,submit = layero.contents().find('#'+ submitID);
						//监听提交
						form.on('submit('+ submitID +')', function(data){
							var field = data.field; //获取提交的字段
							//提交 Ajax 成功后，静态更新表格中的数据
							$.ajax({
								type : 'post',
								url : basePath + '/postGroup/savePost',
								data: {
									"postName" :$("#userName").val(),
									"type":$("#postType").val(),
									"groupId":$("#groupId").val(),
									"roleType":2
								},
								success:function(result){
									if(result.success){
										table.reload('LAY-post-detail'); //数据刷新
										layer.close(index); //关闭弹层
										clean_form("add_user_from");//清空表单
									}else{
										layer.msg(result.msg,{icon: 7});
									}
								}
							});
						});
						submit.trigger('click');
					}
				});
				clean_form("add_user_from");//清空表单
			}
        });
     	// 岗位table监听操作列
        table.on('tool(LAY-post-detail)', function(obj){
          var data = obj.data;
          if(obj.event === 'editPost'){
            	form.val('edit_detail_from',data); // 填充原值
			  	//layer.config()
			  layer.confirm("确认要删除吗，删除后不能恢复", { title: "删除确认" },function (index) {
				  $.ajax({
					  type : 'post',
					  url : basePath + '/postGroup/deleteInfo',
					  data: {
					  	"id":data.id
					  },
					  success:function(result){
						  if(result.success){
							  table.reload('LAY-post-detail'); //数据刷新
							  layer.close(index); //关闭弹层
							  clean_form("edit_detail_from");//清空表单
						  }else{
							  layer.msg(result.msg,{icon: 7});
						  }
					  }
				  });
			  });
            	/*layer.open({
    	        	  type: 1
    	        	  ,title: '编辑岗位'
    	        	  ,content: $('#edit_detail_from')
    	        	  ,area: layui.admin.screen() < 2 ? ['80%', '300px'] : ['420px','300px']
    	        	  ,btn: ['确定', '取消']
    	        	  ,btnAlign: 'c'
    	        	  ,yes: function(index, layero){
    	        		  var submitID = 'edit_detail_from_submit'
    	            		,submit = layero.contents().find('#'+ submitID);
    	        		  //监听提交
    	        		  form.on('submit('+ submitID +')', function(data){
    	        			  var field = data.field; //获取提交的字段
    	        			  //提交 Ajax 成功后，静态更新表格中的数据
    	        			  $.ajax({
    	        				  type : 'post',
    	        				  url : basePath + '/post/save',
    	        				  data: field,
    	        				  success:function(result){
    	        					  if(result.success){
    	        						  table.reload('LAY-post-detail'); //数据刷新
    	        						  layer.close(index); //关闭弹层
    	        						  clean_form("edit_detail_from");//清空表单
    	        					  }else{
    	        						  layer.msg(result.msg,{icon: 7});
    	        					  }
    	        				  }
    	              		 });
    	            	});
    	            submit.trigger('click');
    	          }
    	        });*/
            }
        });
    // 按钮事件
    var active = {
      add: function(){
   	    clean_form("add_form");//清空表单
		form.render();
		  layer.open({
			  type: 1
			  ,title: '新增审批角色'
			  ,content: $('#add_form')
			  ,area: layui.admin.screen() < 2 ? ['80%', '500px'] : ['500px','500px']
			  ,btn: ['确定', '取消']
			  ,btnAlign: 'c'
			  ,yes: function(index, layero){
				  var submitID = 'add_form_submit'
						  ,submit = layero.contents().find('#'+ submitID);
				  //监听提交
				  form.on('submit('+ submitID +')', function(data){
					  var field = data.field; //获取提交的字段
					  //提交 Ajax 成功后，静态更新表格中的数据
					  $.ajax({
						  type : 'post',
						  url : basePath + '/postGroup/save',
						  data: field,
						  success:function(result){
							  if(result.success){
								  table.reload('LAY-dept-manage'); //数据刷新
								  clean_form("add_form");//清空表单
								  layer.close(index); //关闭弹层
							  }else{
								  layer.msg(result.msg,{icon: 7});
							  }
						  }
					  });
				  });
				  submit.trigger('click');
			  }
		  });
		  clean_form("add_form");//清空表单

      }
    }
    // data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });


  });

	//添加验证
  	function verify(obj,verType){
		var $ = layui.$;
		if(obj.value != null && obj.value != ''){
			$(obj).attr("lay-verify",verType);
		}else{
			$(obj).removeAttr("lay-verify");
		}
	}
	var postData;
	function changePost() {
		var $ = layui.$;
		console.log($("#postName").val());
		$("#search_text").html("");
		if($("#postName").val()==''){
			layer.msg("请输入岗位名称",{icon: 7});
			return;
		}
		if($("#postType").val()==''){
			layer.msg("请选择审批范围",{icon: 7});
			return;
		}
		$.ajax({
			type : 'post',
			url : basePath + '/post/getPostByName',
			data : {
				"postName" :$("#postName").val(),
				"type":$("#postType").val(),
				"roleType":1
			},
			success:function(result){
				console.log(result)
				if(result.flag==true){
					$("#search_text").html("查询到岗位"+result.postInfos.length+"个");
					postData=result.postInfos;
				}else{
					layer.msg(result.msg,{icon: 7});
				}
			}
		});
	}

	function changeUser() {
		var $ = layui.$;
		$("#search_text2").html("");
		if($("#userName").val()==''){
			layer.msg("请输入人员姓名",{icon: 7});
			return;
		}
		if($("#postType").val()==''){
			layer.msg("请选择审批范围",{icon: 7});
			return;
		}
		$.ajax({
			type : 'post',
			url : basePath + '/post/getPostByName',
			data : {
				"postName" :$("#userName").val(),
				"type":$("#postType").val(),
				"roleType":2
			},
			success:function(result){
				console.log(result)
				if(result.flag==true){
					$("#search_text2").html("查询到人员"+result.postInfos.length+"人");
					postData=result.postInfos;
				}else{
					layer.msg(result.msg,{icon: 7});
				}
			}
		});
	}
  </script>
</body>
</html>

